import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:flutter/services.dart';
import 'package:flutter_network/request_data_model.dart';
import 'package:flutter_network/service_method.dart';
import 'package:flutter_network/service_url.dart';
import 'package:wallet_utils/login_utils.dart';
import 'package:shared_preferences/shared_preferences.dart';

class VRShowManager {
  static String testUrl = 'http://10.16.47.112:25300/partner/vr/getTakeToken';

  //获取vr sdk token
  static void getVrsDKToken() async {
    Response response =
        await HttpRequest().requestGet(VRShowPath.get360VrToken);

    RequestDataModel? dataModel = RequestDataModel.fromMap(response.data);
    if (dataModel?.code == 200) {
      LogUtil.d('--------1');
      LogUtil.d(dataModel?.data);
      String token = dataModel?.data;
      SharedPreferences preferences = await SharedPreferences.getInstance();
      preferences.setString('vrToken', token);

      /*登录vrSDK*/
      const MethodChannel _channel = MethodChannel('native');
      Map<String, dynamic> param = {
        'isLogin': true,
        'token': token,
        'userId': await LoginUtils.getUserId(),
      };
      _channel.invokeMethod('vrShow', param);
    } else {
      LogUtil.d('--------   1 错了:${dataModel?.msg}');
    }
  }

  /*注销vrSDK*/
  static void vrsDKLoginOut() async {
    const MethodChannel _channel = MethodChannel('native');
    Map<String, dynamic> param = {
      'isLogin': false,
    };
    _channel.invokeMethod('vrShow', param);
  }
}
